What is remove-bom-stream?
The remove-bom-stream npm package is designed to remove Byte Order Marks (BOM) from streams. BOMs are special markers at the start of a text stream that indicate the encoding used. This package is particularly useful when dealing with text files that may have BOMs, which can cause issues in processing or parsing the text.
What are remove-bom-stream's main functionalities?
Remove BOM from a stream
This feature allows you to remove the BOM from a readable stream and pipe the cleaned data into a writable stream. In this example, the BOM is removed from 'input.txt' and the result is written to 'output.txt'.
const fs = require('fs');
const removeBomStream = require('remove-bom-stream');
fs.createReadStream('input.txt')
.pipe(removeBomStream())
.pipe(fs.createWriteStream('output.txt'));
Other packages similar to remove-bom-stream
strip-bom-stream
The strip-bom-stream package also removes BOM from streams. It is similar to remove-bom-stream in functionality but may have different performance characteristics or additional features. Both packages are used to clean BOMs from text streams, making them suitable for similar use cases.
strip-bom
The strip-bom package is used to remove BOM from strings and buffers rather than streams. While it serves a similar purpose, it is more suitable for scenarios where you are dealing with text data in memory rather than streaming data.
remove-bom-stream
Remove a UTF8 BOM at the start of the stream.
Usage
var fs = require('fs');
var concat = require('concat-stream');
var removeBOM = require('remove-bom-stream');
fs.createReadStream('utf8-file-with-bom.txt')
.pipe(removeBOM())
.pipe(concat(function(result) {
}));
API
removeBOM()
Returns a through2
stream that will remove a BOM, given the data is a UTF8 Buffer with a BOM at the beginning. If the data is not UTF8 or does not have a BOM, the data is not changed and this becomes a normal passthrough stream.
License
MIT